package com.orderSystem;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class FormData2Dic
{
	 public static Map<String,String> formData2Dic(String formData ) {                            //报文体处理
	        Map<String,String> result = new HashMap<>();
	        if(formData== null || formData.trim().length() == 0) {
	            return result;
	        }
	        final String[] items = formData.split("&");
	        Arrays.stream(items).forEach(item ->{
	            final String[] keyAndVal = item.split("=");
	            if( keyAndVal.length == 2) {
	                try{
	                    final String key = URLDecoder.decode( keyAndVal[0],"utf8");
	                    final String val = URLDecoder.decode( keyAndVal[1],"utf8");
	                    result.put(key,val);
	                }catch (UnsupportedEncodingException e) {}
	            }
	        });
	        return result;
	    }
}
